<?php include('header.php');?>
<?php 
if($_GET['action']=='add'){
	if($_POST['group_name']!=""){
		$Query = mysql_query("SELECT group_detail_name FROM group_detail WHERE group_detail_name = '".$_POST["group_name"]."' ");
		$Num = mysql_num_rows($Query);
		if($Num>='1'){
			$save = "ชื่อนี้มีอยู่แล้วกรุณาใช้ชื่ออื่นค่ะ";
			$group_name = $_POST['group_name'];
		} else {
			$QueryAdd = mysql_query("INSERT INTO group_detail (group_detail_name) VALUES ('".$_POST["group_name"]."')");
			if($QueryAdd){
				$gQuery = mysql_query("SELECT max(group_detail_id) as group_detail_id FROM group_detail");
				$gRow = mysql_fetch_array($gQuery);
				$rQuery = mysql_query("SELECT roomtype_id FROM roomtype");
					while($rRow = mysql_fetch_array($rQuery)){
						mysql_query("INSERT INTO group_detail_room (group_detail_id,roomtype_id) VALUES ('".$gRow['group_detail_id']."','".$rRow["roomtype_id"]."')");
					}
					
				$save = "<script>window.location='group_price_edit.php?id=".$gRow['group_detail_id']."'</script>";
			}
		}
	}
}
?>
<body onload="focus_text('group_name');">
<form action="?action=add" name="formadd" method="post" id="formadd">
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
    <div class="heading"><h1>เพิ่มบริษัททัวร์</h1>
    <div class="buttons"><a onclick="chk_form('formadd');" class="button"><span>บันทึก</span></a><a onclick="window.location = 'group_manage.php';" class="button"><span>ยกเลิก</span></a></div>
    </div>
  <div class="content">
    <table class="form">
       <tr>
        <td>ชื่อบริษัททัวร์ : </td>
        <td><input name="group_name" type="text" id="group_name" class="vd_form" value="<?php echo $group_name;?>" maxlength="100" onkeyup="IsScharacter(this.value,this)" /></td>
      </tr>
    </table>
	<?php echo "<br><font color=\"red\"><center>$save</center></font>"; ?>
  </div>
</div>
</form>  
  </div>
</div>

</body>
<?php include('footer.php');?>
